package ma.ensao.evalmetrics.util.javaProjects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/*
* Calcule la metrique APF
*/
public class APFMetric {
	File sourceFile;
	double apf= 0;
	public double getApf() {
		return apf;
	}
	public void setApf(double apf) {
		this.apf = apf;
	}
	public APFMetric(File file) throws FileNotFoundException, IOException{
		setSourceFile(file);
		JavaMethodsAttributes JM= new JavaMethodsAttributes(sourceFile);
		JM.setSourceFile(sourceFile);
		JM.countAttributes();
		JM.countProtectedAttributes();
		// Calcule APF pour tout les classes
		double nmbre=0;
		for (int i = 0; i < JM.getNumberClasses(); i++) {
			if (JM.getNumberProtectedAttributes()[i]==0 || JM.getNumberAttributes()[i]==0){
				nmbre=0;
				apf +=nmbre; 
			}else{
				nmbre =(double) JM.getNumberProtectedAttributes()[i]/JM.getNumberAttributes()[i];
				apf +=nmbre; 
			}
		}
		// Calcul la moyenne de APF
		System.out.println("apfff"+apf);
		setApf(apf/JM.getNumberClasses());
	}
	public File getSourceFile() {
		return sourceFile;
	}
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}
}
